#include "wxspagesetupdialog.h"
#include "../wxsitemresdata.h"
#include <wx/printdlg.h>
#include <prep.h>

namespace {
  wxsRegisterItem<wxsPageSetupDialog> Reg( _T( "PageSetupDialog" ), _T( "动画控制" ), wxsTTool, _T( "对话框" ), 130, false );
}

wxsPageSetupDialog::wxsPageSetupDialog( wxsItemResData* Data ):
  wxsTool( Data, &Reg.Info ),
  m_bEnableHelp( false ),
  m_bEnableMargins( true ),
  m_bEnableOrientation( true ),
  m_bEnablePaper( true ),
  m_bDefaultInfo( false ),
  m_bDefaultMinMargins( false ),
  m_bEnablePrinter( true ),
  m_iMarginLeft( -1 ),
  m_iMarginTop( -1 ),
  m_iMarginRight( -1 ),
  m_iMarginBottom( -1 ),
  m_iMarginMinLeft( -1 ),
  m_iMarginMinTop( -1 ),
  m_iMarginMinRight( -1 ),
  m_iMarginMinBottom( -1 ),
  m_iPaperID( wxPAPER_NONE ),
  m_iPaperWidth( -1 ),
  m_iPaperHeight( -1 ) {
  arrPaperIDs.Add( wxT( "wxPAPER_NONE" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_LETTER" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_LEGAL" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_A4" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_CSHEET" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_DSHEET" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ESHEET" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_LETTERSMALL" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_TABLOID" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_LEDGER" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_STATEMENT" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_EXECUTIVE" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_A3" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_A4SMALL" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_A5" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_B4" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_B5" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_FOLIO" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_QUARTO" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_10X14" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_11X17" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_NOTE" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_9" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_10" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_11" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_12" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_14" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_DL" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_C5" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_C3" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_C4" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_C6" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_C65" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_B4" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_B5" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_B6" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_ITALY" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_MONARCH" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_ENV_PERSONAL" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_FANFOLD_US" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_FANFOLD_STD_GERMAN" ) );
  arrPaperIDs.Add( wxT( "wxPAPER_FANFOLD_LGL_GERMAN" ) );
}


void wxsPageSetupDialog::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/printdlg.h>" ), GetInfo().ClassName, hfInPCH );
      wxString sDataName = GetCoderContext()->GetUniqueName( _T( "pageSetupDialogData" ) );
      AddDeclaration( wxString::Format( wxT( "wxPageSetupDialogData  *%s;" ), sDataName.wx_str() ) );
      Codef( _T( "\t%s = new wxPageSetupDialogData;\n" ), sDataName.wx_str() );
      if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
        if( m_bEnableHelp ) {
          Codef( _T( "\t%s->EnableHelp(%b);\n" ), sDataName.wx_str(), m_bEnableHelp );
        }
        if( !m_bEnableMargins ) {
          Codef( _T( "\t%s->EnableMargins(%b);\n" ), sDataName.wx_str(), m_bEnableMargins );
        }
        if( !m_bEnableOrientation ) {
          Codef( _T( "\t%s->EnableOrientation(%b);\n" ), sDataName.wx_str(), m_bEnableOrientation );
        }
        if( !m_bEnablePaper ) {
          Codef( _T( "\t%s->EnablePaper(%b);\n" ), sDataName.wx_str(), m_bEnablePaper );
        }
        if( m_bDefaultInfo ) {
          Codef( _T( "\t%s->SetDefaultInfo(%b);\n" ), sDataName.wx_str(), m_bDefaultInfo );
        }
        if( m_bDefaultMinMargins ) {
          Codef( _T( "\t%s->SetDefaultMinMargins(%b);\n" ), sDataName.wx_str(), m_bDefaultMinMargins );
        }
      }
      if( !m_bEnablePrinter ) {
        Codef( _T( "\t%s->EnablePrinter(%b);\n" ), sDataName.wx_str(), m_bEnablePrinter );
      }
      if( m_iMarginLeft > -1 && m_iMarginTop > -1 ) {
        Codef( _T( "\t%s->SetMarginTopLeft(wxPoint(%d, %d));\n" ), sDataName.wx_str(), m_iMarginLeft, m_iMarginTop );
      }
      if( m_iMarginRight > -1 && m_iMarginBottom > -1 ) {
        Codef( _T( "\t%s->SetMarginBottomRight(wxPoint(%d, %d));\n" ), sDataName.wx_str(), m_iMarginRight, m_iMarginBottom );
      }
      if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
        if( m_iMarginMinLeft > -1 && m_iMarginMinTop > -1 ) {
          Codef( _T( "\t%s->SetMinMarginTopLeft(wxPoint(%d, %d));\n" ), sDataName.wx_str(), m_iMarginMinLeft, m_iMarginMinTop );
        }
        if( m_iMarginMinRight > -1 && m_iMarginMinBottom > -1 ) {
          Codef( _T( "\t%s->SetMinMarginBottomRight(wxPoint(%d, %d));\n" ), sDataName.wx_str(), m_iMarginMinRight, m_iMarginMinBottom );
        }
      }
      if( m_iPaperID != wxPAPER_NONE ) {
        Codef( _T( "\t%s->SetPaperId(%s);\n" ), sDataName.wx_str(), arrPaperIDs[m_iPaperID].wx_str() );
      } else {
        if( m_iPaperWidth != -1 && m_iPaperHeight != -1 ) {
          Codef( _T( "\t%s->SetPaperSize(wxSize(%d, %d));\n" ), sDataName.wx_str(), m_iPaperWidth, m_iPaperHeight );
        }
      }
      Codef( _T( "%C(%W, %s);\n" ), sDataName.wx_str() );
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsPageSetupDialog::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}


void wxsPageSetupDialog::OnEnumToolProperties( M_Code_unused long Flags ) {
  static const long PaperIDs[] = {
    wxPAPER_NONE,
    wxPAPER_LETTER,
    wxPAPER_LEGAL,
    wxPAPER_A4,
    wxPAPER_CSHEET,
    wxPAPER_DSHEET,
    wxPAPER_ESHEET,
    wxPAPER_LETTERSMALL,
    wxPAPER_TABLOID,
    wxPAPER_LEDGER,
    wxPAPER_STATEMENT,
    wxPAPER_EXECUTIVE,
    wxPAPER_A3,
    wxPAPER_A4SMALL,
    wxPAPER_A5,
    wxPAPER_B4,
    wxPAPER_B5,
    wxPAPER_FOLIO,
    wxPAPER_QUARTO,
    wxPAPER_10X14,
    wxPAPER_11X17,
    wxPAPER_NOTE,
    wxPAPER_ENV_9,
    wxPAPER_ENV_10,
    wxPAPER_ENV_11,
    wxPAPER_ENV_12,
    wxPAPER_ENV_14,
    wxPAPER_ENV_DL,
    wxPAPER_ENV_C5,
    wxPAPER_ENV_C3,
    wxPAPER_ENV_C4,
    wxPAPER_ENV_C6,
    wxPAPER_ENV_C65,
    wxPAPER_ENV_B4,
    wxPAPER_ENV_B5,
    wxPAPER_ENV_B6,
    wxPAPER_ENV_ITALY,
    wxPAPER_ENV_MONARCH,
    wxPAPER_ENV_PERSONAL,
    wxPAPER_FANFOLD_US,
    wxPAPER_FANFOLD_STD_GERMAN,
    wxPAPER_FANFOLD_LGL_GERMAN
  };
  static const wxChar* PaperIDNames[]  = {
    _T( "Use specific dimensions" ),
    _T( "Letter, 8 1/2 by 11 inches" ),
    _T( "Legal, 8 1/2 by 14 inches" ),
    _T( "A4 Sheet, 210 by 297 millimeters" ),
    _T( "C Sheet, 17 by 22 inches" ),
    _T( "D Sheet, 22 by 34 inches" ),
    _T( "E Sheet, 34 by 44 inches" ),
    _T( "Letter Small, 8 1/2 by 11 inches" ),
    _T( "Tabloid, 11 by 17 inches" ),
    _T( "Ledger, 17 by 11 inches" ),
    _T( "Statement, 5 1/2 by 8 1/2 inches" ),
    _T( "Executive, 7 1/4 by 10 1/2 inches" ),
    _T( "A3 sheet, 297 by 420 millimeters" ),
    _T( "A4 small sheet, 210 by 297 millimeters" ),
    _T( "A5 sheet, 148 by 210 millimeters" ),
    _T( "B4 sheet, 250 by 354 millimeters" ),
    _T( "B5 sheet, 182-by-257-millimeter paper" ),
    _T( "Folio, 8-1/2-by-13-inch paper" ),
    _T( "Quarto, 215-by-275-millimeter paper" ),
    _T( "10-by-14-inch sheet" ),
    _T( "11-by-17-inch sheet" ),
    _T( "Note, 8 1/2 by 11 inches" ),
    _T( "#9 Envelope, 3 7/8 by 8 7/8 inches" ),
    _T( "#10 Envelope, 4 1/8 by 9 1/2 inches" ),
    _T( "#11 Envelope, 4 1/2 by 10 3/8 inches" ),
    _T( "#12 Envelope, 4 3/4 by 11 inches" ),
    _T( "#14 Envelope, 5 by 11 1/2 inches" ),
    _T( "DL Envelope, 110 by 220 millimeters" ),
    _T( "C5 Envelope, 162 by 229 millimeters" ),
    _T( "C3 Envelope, 324 by 458 millimeters" ),
    _T( "C4 Envelope, 229 by 324 millimeters" ),
    _T( "C6 Envelope, 114 by 162 millimeters" ),
    _T( "C65 Envelope, 114 by 229 millimeters" ),
    _T( "B4 Envelope, 250 by 353 millimeters" ),
    _T( "B5 Envelope, 176 by 250 millimeters" ),
    _T( "B6 Envelope, 176 by 125 millimeters" ),
    _T( "Italy Envelope, 110 by 230 millimeters" ),
    _T( "Monarch Envelope, 3 7/8 by 7 1/2 inches" ),
    _T( "6 3/4 Envelope, 3 5/8 by 6 1/2 inches" ),
    _T( "US Std Fanfold, 14 7/8 by 11 inches" ),
    _T( "German Std Fanfold, 8 1/2 by 12 inches" ),
    _T( "German Legal Fanfold, 8 1/2 by 13 inches" ),
    NULL
  };
  if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
    WXS_BOOL( wxsPageSetupDialog, m_bDefaultInfo, _T( "Default Info" ), _T( "default_info" ), false )
    WXS_BOOL( wxsPageSetupDialog, m_bEnableHelp, _T( "Enable Help" ), _T( "enable_help" ), false )
    WXS_BOOL( wxsPageSetupDialog, m_bEnableMargins, _T( "Enable Margins" ), _T( "enable_margins" ), true )
  }
  WXS_LONG( wxsPageSetupDialog, m_iMarginLeft,  _T( "Margin Left (mm)" ), _T( "margin_left" ), -1 )
  WXS_LONG( wxsPageSetupDialog, m_iMarginTop,  _T( "Margin Top (mm)" ), _T( "margin_top" ), -1 )
  WXS_LONG( wxsPageSetupDialog, m_iMarginRight,  _T( "Margin Right (mm)" ), _T( "margin_right" ), -1 )
  WXS_LONG( wxsPageSetupDialog, m_iMarginBottom,  _T( "Margin Bottom (mm)" ), _T( "margin_bottom" ), -1 )
  if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
    WXS_BOOL( wxsPageSetupDialog, m_bDefaultMinMargins, _T( "Default Min. Margins" ), _T( "default_min_margins" ), false )
    WXS_LONG( wxsPageSetupDialog, m_iMarginMinLeft,  _T( "Min. Margin Left (mm)" ), _T( "min_margin_left" ), -1 )
    WXS_LONG( wxsPageSetupDialog, m_iMarginMinTop,  _T( "Min. Margin Top (mm)" ), _T( "min_margin_top" ), -1 )
    WXS_LONG( wxsPageSetupDialog, m_iMarginMinRight,  _T( "Min. Margin Right (mm)" ), _T( "min_margin_right" ), -1 )
    WXS_LONG( wxsPageSetupDialog, m_iMarginMinBottom,  _T( "Min. Margin Bottom (mm)" ), _T( "min_margin_bottom" ), -1 )
  }
  if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
    WXS_BOOL( wxsPageSetupDialog, m_bEnableOrientation, _T( "Enable Orientation" ), _T( "enable_orientation" ), true )
    WXS_BOOL( wxsPageSetupDialog, m_bEnablePaper, _T( "Enable Paper" ), _T( "enable_paper" ), true )
  }
  WXS_ENUM( wxsPageSetupDialog, m_iPaperID, _T( "Paper ID" ), _T( "paper_id" ), PaperIDs, PaperIDNames, wxPAPER_NONE )
  WXS_LONG( wxsPageSetupDialog, m_iPaperWidth,  _T( "Paper Width" ), _T( "paper_width" ), -1 )
  WXS_LONG( wxsPageSetupDialog, m_iPaperHeight,  _T( "Paper Height" ), _T( "paper_height" ), -1 )
  WXS_BOOL( wxsPageSetupDialog, m_bEnablePrinter, _T( "Enable Printer" ), _T( "enable_printer" ), true )
}
